<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>安伴后台管理系统-管理员列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <script type="text/javascript" src="/static/js/jquery.cookie.js"></script>
    <script type="text/javascript" src="/static/js/base64.decode.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="/admin">首页</a>
            <a><cite>管理员</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="{{urlfor "admin.UserAdminController.ShowList"}}"
       title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5" id="search-form" method="post" action="{{urlfor "admin.UserAdminController.ShowList"}}">
                        {{.xsrfdata}}
                        <input type="hidden" name="p" id="cur-page" value="1">
                    </form>
                </div>
                <div class="layui-card-header">
                    {{/*<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>*/}}
                    <button class="layui-btn" onclick="xadmin.open('添加用户','{{urlfor "admin.UserAdminController.Add"}}')"><i
                                class="layui-icon"></i>添加
                    </button>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>登录名</th>
                            <th>角色</th>
                            <th>姓名</th>
                            <th>手机</th>
                            <th>邮箱</th>
                            <th>创建时间</th>
                            <th>状态</th>
                            <th>操作</th>
                        </thead>
                        <tbody>
                        {{range .recordList}}
                            <tr>
                                <td>{{.Id}}</td>
                                <td>{{.Account}}</td>
                                <td>{{.UserAdminRole.Name}}</td>
                                <td>{{.RealName}}</td>
                                <td>{{.Mobile}}</td>
                                <td>{{.Email}}</td>
                                <td>{{.CreatedShow}}</td>
                                <td class="td-status">
                                    {{if eq .Status 1}}
                                        <span class="layui-btn layui-btn-normal layui-btn-mini">{{.StatusShow}}</span>
                                    {{else}}
                                        <span class="layui-btn layui-btn-disabled layui-btn-mini">{{.StatusShow}}</span>
                                    {{end}}
                                </td>
                                <td class="td-manage">
                                    <a onclick="member_stop(this,'{{.Id}}', '{{.Status}}')" href="javascript:;"
                                       title="启用/禁用">
                                        <i class="layui-icon">&#xe601;</i>
                                    </a>
                                    <a title="编辑" onclick="xadmin.open('编辑','{{urlfor "admin.UserAdminController.Edit" ":id" .Id}}')"
                                       href="javascript:;">
                                        <i class="layui-icon">&#xe642;</i>
                                    </a>
                                </td>
                            </tr>
                        {{end}}
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        <div>
                            {{str2html .paginator}}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>

    layui.use(["form"], function () {
        $ = layui.jquery;
        $(".page").on("click", "a", function () {
            var n = $(this).attr("page-num");
            $("#cur-page").val(n);
            $("#search-form").submit();
        });
    });

    var canSubmit = true;

    /*用户-停用*/
    function member_stop(obj, id, status) {
        var t = status == '1' ? "禁用" : "启用";
        layer.confirm('确认要' + t + '吗？', function (index) {

            layui.use(['layer'], function () {

                $ = layui.jquery;
                var layer = layui.layer,
                    xsrf = base64_decode(Cookies.get("_xsrf").split("|")[0]);

                if (!canSubmit) return false;
                var loadIndex = layer.load();
                canSubmit = false;

                $.ajax({
                    url: "{{urlfor "admin.UserAdminController.StatusSwitch"}}",
                    type: "POST",
                    data: {_xsrf: xsrf, id: id, status: status == 1 ? 0 : 1},
                    dataType: "json",
                    success: function (res) {

                        layer.close(loadIndex);
                        canSubmit = true;

                        if (res.status != 1) {
                            layer.msg(res.msg, {icon: 2});
                            return false;
                        }

                        layer.alert(res.msg, {icon: 6}, function () {
                            //关闭当前frame
                            xadmin.close();
                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                        });

                    }
                });
            });

        });
    }

</script>
</html>